import {
	baseUrl
} from '@/env.js'

const request = (method, url, data = {}, header = {}) => {
	header.token = uni.getStorageSync('token')

	url = baseUrl + (/^\//.test(url) ? url : `/${url}`)
	return new Promise(function(resolve, reject) {
		uni.request({
			url,
			data,
			dataType: 'json',
			header,
			method,
			responseType: 'text',
			success: (res) => {
				resolve(res.data)
			},
			fail: (error) => {
				reject(error)
			},
		})
	})
}

function Get(url, data, header) {
	return request('GET', url, data, header)
}

function Post(url, data, header) {
	return request('POST', url, data, header)
}
export default {
	Get,
	Post
}
